#pragma config(Sensor, in1,    lineFollowerRIGHT, sensorLineFollower)
#pragma config(Sensor, in2,    lineFollowerCENTER, sensorLineFollower)
#pragma config(Sensor, in3,    lineFollowerLEFT, sensorLineFollower)
#pragma config(Sensor, dgtl1,  rightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  leftEncoder,    sensorQuadEncoder)
#pragma config(Motor,  port1,           rightMotor,    tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port10,          leftMotor,     tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int x,y;

int threshold = 2600;

task main()
{
		while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerRIGHT] <= threshold || SensorValue[lineFollowerLEFT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
  	motor[leftMotor] = 63;
		motor[rightMotor] = 63;
		wait1Msec(500);
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;
		wait1Msec(1000);

		SensorValue[rightEncoder] = 0;
		SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];

		while (SensorValue[rightEncoder] <= 382 || SensorValue[leftEncoder] >= -382)
		{
			x=SensorValue[leftEncoder];
			y=SensorValue[rightEncoder];
			motor[leftMotor] = -80;
			motor[rightMotor] = 80;
			if(SensorValue[rightEncoder] >= 382) {
				motor[rightMotor] = 0;
			}
			if(SensorValue[leftEncoder] <= -382)
			{
				motor[leftMotor] = 0;
	}

}
      while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerRIGHT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
	motor[leftMotor] = 63;
		motor[rightMotor] = 63;
		wait1Msec(500);
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;
		wait1Msec(1000);

		SensorValue[rightEncoder] = 0;
		SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];


	while (SensorValue[rightEncoder] >= -382 || SensorValue[leftEncoder] <= 382)
	{
		x=SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];
		motor[leftMotor] = 80;
		motor[rightMotor] = -80;
		if(SensorValue[rightEncoder] <= -382) {
			motor[rightMotor] = 0;
		}
		if(SensorValue[leftEncoder] >= 382)
		{
			motor[leftMotor] = 0;
}
}
  while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerRIGHT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
	motor[leftMotor] = 63;
		motor[rightMotor] = 63;
		wait1Msec(500);
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;
		wait1Msec(1000);

		SensorValue[rightEncoder] = 0;
		SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];


	while (SensorValue[rightEncoder] >= -382 || SensorValue[leftEncoder] <= 382)
	{
		x=SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];
		motor[leftMotor] = 80;
		motor[rightMotor] = -80;
		if(SensorValue[rightEncoder] <= -382) {
			motor[rightMotor] = 0;
		}
		if(SensorValue[leftEncoder] >= 382)
		{
			motor[leftMotor] = 0;
}
}
motor[leftMotor] = 0;
motor[rightMotor] = 0;
wait1Msec(2000);

	SensorValue[rightEncoder] = 0;
	SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];


	while (SensorValue[rightEncoder] >= -382 || SensorValue[leftEncoder] <= 382)
	{
		x=SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];
		motor[leftMotor] = 80;
		motor[rightMotor] = -80;
		if(SensorValue[rightEncoder] <= -382) {
			motor[rightMotor] = 0;
		}
		if(SensorValue[leftEncoder] >= 382)
		{
			motor[leftMotor] = 0;
}
}

while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerLEFT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
	motor[leftMotor] = 63;
		motor[rightMotor] = 63;
		wait1Msec(500);
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;
		wait1Msec(1000);

		SensorValue[rightEncoder] = 0;
		SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];

		while (SensorValue[rightEncoder] <= 382 || SensorValue[leftEncoder] >= -382)
		{
			x=SensorValue[leftEncoder];
			y=SensorValue[rightEncoder];
			motor[leftMotor] = -80;
			motor[rightMotor] = 80;
			if(SensorValue[rightEncoder] >= 382) {
				motor[rightMotor] = 0;
			}
			if(SensorValue[leftEncoder] <= -382)
			{
				motor[leftMotor] = 0;
	}

}
     while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerRIGHT] <= threshold || SensorValue[lineFollowerLEFT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
  	motor[leftMotor] = 63;
		motor[rightMotor] = 63;
		wait1Msec(500);
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;
		wait1Msec(1000);

	SensorValue[rightEncoder] = 0;
	SensorValue[leftEncoder] = 0;

		x= SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];


	while (SensorValue[rightEncoder] >= -382 || SensorValue[leftEncoder] <= 382)
	{
		x=SensorValue[leftEncoder];
		y=SensorValue[rightEncoder];
		motor[leftMotor] = 80;
		motor[rightMotor] = -80;
		if(SensorValue[rightEncoder] <= -382) {
			motor[rightMotor] = 0;
		}
		if(SensorValue[leftEncoder] >= 382)
		{
			motor[leftMotor] = 0;
}
}

while (SensorValue[lineFollowerCENTER] <= threshold || SensorValue[lineFollowerRIGHT] <= threshold || SensorValue[lineFollowerLEFT] <= threshold)
		{

			// RIGHT sensor sees dark:
			if(SensorValue(lineFollowerRIGHT) > threshold)
			{
				// counter-steer right:

				motor[leftMotor]  = 63;
				motor[rightMotor] = 30;
			}
			// CENTER sensor sees dark:
			if(SensorValue(lineFollowerCENTER) > threshold)
			{
				// go straight
				motor[leftMotor]  = 63;
				motor[rightMotor] = 63;
			}
			// LEFT sensor sees dark:
			if(SensorValue(lineFollowerLEFT) > threshold)
			{
				// counter-steer left:
				motor[leftMotor]  = 30;
				motor[rightMotor] = 63;

		}
}
}
